{% extends "UiManager/base.html" %}
{% block title %}用例管理{% endblock %}
{% block new %}
    <a href="/ui/add_case/">
    <button class="btn btn-danger btn-sm fa fa-plus" style="border-radius: 20px" data-toggle="modal" data-target="#newProject">&nbsp;新建用例</button>
    </a>
{% endblock %}
{% block location %}
    <div class="am-icon-home fa fa-home" style="font-weight: bold;color: grey; float: right;">&nbsp;当前位置： 用例管理 > 用例列表</div>
{% endblock %}
{% load staticfiles %}
{% block css %}
{% endblock %}
{% block js %}
    <script>

    /*删除询问方法*/
    function isDel(id) {
        $("#delButton").attr("onclick", "del(" + id + ")");
        $("#deleteObj").modal("show");
    }

    /*删除方法*/
    function del(id) {
        var data = {
          "id": id,
          "type": "delete"
        };
        $.ajax({
            url: '/ui/edit_case/',
            type: 'post',
            contentType: 'application/json',
            dataType: 'json',
            data:JSON.stringify(data),
            success: function (res) {
                if (res.code == 0) {
                    $("#deleteObj").modal("hide");
                    location.reload();
                } else {
                    $("#delMessage").html(res.message);
                }
            }
        });
    }

    /*删除弹窗取消*/
    function closeDown() {
        $("#delMessage").html("");
        $("#deleteObj").modal('hide')           //删除提示信息
    }


</script>
{% endblock %}
{% block content %}
    <div id="page-wrapper">
        <div id="page-inner">
            <!-- /. 表格  -->
            <div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <!--<div class="panel-heading">表格名字</div>-->
                        <div class="panel-body" style="min-height:500px">
                            <div class="row mar-bottom-20">
                                <div class="form-inline">
                                    <form id="pro_filter" method="POST" action="/ui/case_list/">
                                        <div class="col-lg-12">
                                            <div class="input-group">
                                                <select class="form-control selectpicker" data-style="btn-danger" name="select_project_name">
                                                    <option value="0">全部项目</option>
                                                    {% for project in project_list %}
                                                        {% if  project.id == select_project_name %}
                                                            <option value="{{ project.id }}" selected="selected">{{ project.project_name }}</option>
                                                        {% else %}
                                                            <option value="{{ project.id }}">{{ project.project_name }}</option>
                                                        {% endif %}
                                                    {% endfor %}
                                                </select>
                                            </div>
                                            <div class="input-group">
                                              <input name="search_case_name" type="text" class="form-control" placeholder="用例名称" value="{{ search_case_name }}">
                                                <span class="input-group-btn">
                                                <button class="btn btn-primary" type="submit">搜索</button>
                                              </span>
                                            </div><!-- /input-group -->
                                        </div><!-- /.col-lg-12 -->
                                    </form>
                                </div>
                            </div>

                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>用例标题</th>
                                        <th>所属项目</th>
                                        <th>描述信息</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody class="js_table">
                                    {% for row in obj %}
                                    <tr>
                                        <td>{{ row.id }}</td>
                                        <td>{{ row.case_name }}</td>
                                        <td>{{ row.belong_project.project_name }}</td>
                                        <td>{{ row.simple_desc }}</td>
                                        <td>{{ row.create_time }}</td>
                                        <td>
                                            <a href="/ui/edit_case/?id={{ row.id }}">
                                                <button class="btn-primary">编辑</button>
                                            </a>
                                            <button class="btn-danger" onclick="isDel('{{ row.id }}')">删除</button>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            <ul class="pagination" id="pager">
                                {#上一页按钮开始#}
                                {# 如果当前页有上一页#}
                                {% if obj.has_previous %}
                                    {#  当前页的上一页按钮正常使用#}
                                    <li class="previous"><a href="/ui/case_list?page={{ obj.previous_page_number }}">&laquo;</a></li>
                                {% else %}
                                    {# 当前页的不存在上一页时,上一页的按钮不可用#}
                                    <li class="previous disabled"><a href="#">&laquo;</a></li>
                                {% endif %}
                                {#上一页按钮结束#}
                                {# 页码开始#}
                                {% for num in paginator.page_range %}

                                    {% if num == currentPage %}
                                        <li class="item active"><a href="/ui/case_list?page={{ num }}">{{ num }}</a></li>
                                    {% else %}
                                        <li class="item"><a href="/ui/case_list?page={{ num }}">{{ num }}</a></li>
                                    {% endif %}
                                {% endfor %}
                                {#页码结束#}
                                {# 下一页按钮开始#}
                                {% if obj.has_next %}
                                    <li class="next"><a href="/ui/case_list?page={{ obj.next_page_number }}">&raquo;</a></li>
                                {% else %}
                                    <li class="next disabled"><a href="#">&raquo;</a></li>
                                {% endif %}
                                {# 下一页按钮结束#}
                            </ul>
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div>
            <!-- /. 表格  -->
        </div>
        <!-- /. PAGE INNER  -->
    </div>
<!--删除询问弹窗提示-->
<div class="modal fade" id="deleteObj" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">删除用例</h4>
            </div>
            <div class="modal-body">
                <p>请确认是否删除用例</p>
                <p id='delMessage' class="js_DELmessage text-danger"></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" onclick="closeDown()">取消</button>
                <button type="button" class="btn btn-primary" id="delButton">确定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!--end 删除询问弹窗提示-->
{% endblock %}
